import { Component } from '@angular/core';
import { IonicPage, ModalController } from 'ionic-angular';
import { LoginPage } from "../login/login";

/**
 * Generated class for the SettingPage page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-setting',
  templateUrl: 'setting.html',
})
export class SettingPage {
  user:any;
  userInfoPage: any;
  myRepositoryPage:any;
  myCustomerPage: any;

  constructor(public modalCtrl: ModalController) {
    this.user = JSON.parse(localStorage.getItem('user'));
    this.user = this.user ? JSON.parse(localStorage.getItem('user')) : [];
    console.log(this.user);
    console.log(this.user.user_id);
    if(this.user.user_id === undefined){
      this.user.avatar='assets/icon/user.jpg';
      this.user.nickname='未名';
      this.user.user_id='未登录';
    }
    this.userInfoPage = 'UserInfoPage';
    this.myRepositoryPage = 'MyRepositoryPage';
    this.myCustomerPage = 'MyCustomerPage';
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad UserInfoPage');
  }
  ionViewWillEnter(){
    //更新用户信息
    this.user = JSON.parse(localStorage.getItem('user'));
    this.user = this.user ? JSON.parse(localStorage.getItem('user')) : [];
    console.log(this.user);
  }
  //注销
  logOut(){
    console.log('注销成功!');
    //删除所有存储
    localStorage.clear();
    this.modalCtrl.create(LoginPage).present();
  }
}
